package fit.conceptmap.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import fit.conceptmap.beans.JsonBean;
import fit.conceptmap.beans.UserBean;
import fit.conceptmap.dao.IShareDao;
import fit.conceptmap.entities.Conceptmap;
import fit.conceptmap.entities.Share;
import fit.conceptmap.services.IShareService;

@Service
public class ShareServiceImpl implements IShareService {

	@Autowired IShareDao shareDao;
	
	@Override
	public List<UserBean> getListMemberByIdConcepMaps(String idConceptMaps) {
		List<UserBean> result = new ArrayList<UserBean>();
		UserBean user;
		for (Share share : shareDao.getListShareByIdConcepMaps(idConceptMaps)) {
			user = new UserBean();
			user.setIdUser(share.getUser().getIdUser());
			user.setFullName(share.getUser().getFullName());
			result.add(user);
		}
		return result;
	}

	@Override
	public boolean share(String idConceptMaps, String idmember) {
		return shareDao.share(idConceptMaps, idmember);
	}

	@Override
	public List<JsonBean> getListShareByIdMember(String username) {
		List<Conceptmap> lst = shareDao.getListShareByIdMember(username);
		List<JsonBean> result = new ArrayList<JsonBean>();
		JsonBean json;
		for (Conceptmap conceptmap : lst) {
			json = new JsonBean();
			json.setDescription(conceptmap.getDescription());
			json.setNameConceptMaps(conceptmap.getName());
			json.setIdConceptMaps(conceptmap.getIdConceptMaps());
			json.setDateCreate(conceptmap.getDateCreate().toString());
			result.add(json);
		}
		return result;
	}

}
